from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("file:///C:/TT/%E4%B9%A0%E7%9F%A5/12/my_test_demo_12/seleniumDemo/selectDemo.html")
time.sleep(2)

# 实例化一个下拉框对象
select_element = driver.find_element(By.CSS_SELECTOR, "select")
select_obj = Select(select_element)
# # 一、通过索引选择
# for i in range(3):
#     select_obj.select_by_index(i)
#     time.sleep(2)
# # 二、select_by_value
# for i in ['shenzheng', 'beijing', 'chengdu']:
#     select_obj.select_by_value(i)
#     time.sleep(2)

# 三、select_by_visible_text
for i in ['深圳', '北京', '成都']:
    select_obj.select_by_visible_text(i)
    time.sleep(2)


time.sleep(3)
driver.quit()